#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "qtactiveobject.h"







MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void MainWindow::reportProgress(int v, int max)
{
    ui->progressBar->setMaximum(max);
    ui->progressBar->setValue(v);
}

void MainWindow::setResult(long long v)
{
    ui->resultLabel->setText(QString("Result : %1").arg(v));
}


void MainWindow::on_pushButton_clicked()
{
    ui->resultLabel->setText("");

    CalculateFactorial* msg = new CalculateFactorial(ui->spinBox->value());
    connect(msg, SIGNAL(progresChanged(int,int)), this, SLOT(reportProgress(int, int)));
    connect(msg, SIGNAL(resultIsReady(long long)), this, SLOT(setResult(long long)));

    aObj.send(msg);

}
